/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package unitedbank;

import java.util.Scanner;

/**
 *
 * @author TQNINH
 */
public class LoanPayment {
    
    public LoanPayment(){
        
    }

    static public float roundOff(double value) {
        value = value * 100;
        float roundedValue = (float) Math.round(value);
        roundedValue = roundedValue / 100;
        return roundedValue;
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        double balance = 0.0f;
        float annualPercenRate = 0.0f;
        float rate = 0.0f;
        int months = 0;
        double EMI = 0;
        Scanner input = new Scanner(System.in);
        
        System.out.print("Enter the original loan amount: ");
        balance = input.nextDouble();
        
        System.out.print("Enter the rate in percentage: ");
        annualPercenRate = input.nextFloat();
        
        System.out.print("Enter the Loan duration in months: ");
        months = input.nextInt();
        
        System.out.println("Computing the monthly loan installment...");
        System.out.println("*********************************************");
        
        rate = (annualPercenRate / 12) / 100;
        EMI = (balance * rate * (Math.pow((1 + rate), months))) /
                ((Math.pow((1 + rate), months)) - 1);
        System.out.println("The calculated EMI for loan payment = $" + EMI);
        
        System.out.println("The exact EMI to be paid = $" + roundOff(EMI));
        
        System.out.println("The Ceiling value for the EMI = $" + Math.ceil(EMI));
        
        System.out.println("The Floor value for the EMI = $" + Math.floor(EMI));
    }
}
